//
//  TaskFooter.m
//  RRQS
//
//  Created by kyjun on 16/3/24.
//
//

#import "TaskFooter.h"

#import "MQGradientProgressView.h"

@interface TaskFooter ()<AMapSearchDelegate>

@property(nonatomic,strong) UIView *addressView;
@property(nonatomic,strong) UIButton* btnIcon;
@property(nonatomic,strong) UILabel* labelSendAddress;
@property(nonatomic,strong) TTTAttributedLabel* labelReGeocode;

@property (nonatomic, strong) AMapSearchAPI *search;


@property(nonatomic,strong) UIView *proView;
@property(nonatomic,strong) TTTAttributedLabel* orderTimeLabel;
@property(nonatomic,strong) TTTAttributedLabel* orderLabel;
@property(nonatomic,strong) TTTAttributedLabel* arriveTimeLabel;
@property(nonatomic,strong) TTTAttributedLabel* arriveLabel;
@property(nonatomic,strong) MQGradientProgressView *progressView;

@property(nonatomic,strong) UIButton* stateBtn;



@property(nonatomic,strong) UIButton* clientBtn;


@property(nonatomic,strong) UIButton* merchantBtn;

@property(nonatomic,strong) UIButton* routeBtn;

@property(nonatomic,strong) UIButton* reachBtn;

@property (nonatomic, assign) BOOL isWaimOrPaot;// YES跑腿       NO 外卖

@end

@implementation TaskFooter

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.backgroundColor = [UIColor colorWithRed:255/255.f green:255/255.f blue:255/255.f alpha:1.0];
        [self layoutUI];
        [self layoutConstraints];
    }
    return self;
}

#pragma mark =====================================================  user inferface layout
-(void)layoutUI{
    
    [self addSubview:self.addressView];
    [self.addressView addSubview:self.btnIcon];
    [self.addressView addSubview:self.labelSendAddress];
    [self.addressView addSubview:self.labelReGeocode];
    
    [self addSubview:self.stateBtn];
    [self addSubview:self.proView];
    [self.proView addSubview:self.arriveLabel];
    [self.proView addSubview:self.orderLabel];
    [self.proView addSubview:self.orderTimeLabel];
    [self.proView addSubview:self.arriveTimeLabel];
    [self.proView addSubview:self.progressView];
    
    [self addSubview:self.reachBtn];
    [self addSubview:self.clientBtn];
    [self addSubview:self.merchantBtn];
    [self addSubview:self.routeBtn];

}

-(void)layoutConstraints{
    
    
    [self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(60);
    }];
    
    [self.btnIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.addressView);
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.left.equalTo(self.addressView).offset(10);
    }];
    
    [self.labelSendAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addressView);
        make.left.equalTo(self.btnIcon.mas_right).offset(10);
        make.right.equalTo(self.addressView).offset(-10);
        make.height.mas_equalTo(30);

    }];
    
    [self.labelReGeocode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labelSendAddress.mas_bottom);
        make.left.equalTo(self.labelSendAddress);
        make.right.equalTo(self.labelSendAddress);
        make.bottom.equalTo(self.addressView);
        
    }];
    
    
    [self.stateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.proView);
        make.right.equalTo(self).offset(-20);
        make.size.mas_equalTo(CGSizeMake(115, 35));
    }];
    
    
    
    float label_h = 40;
    float label_w = 80;
    float progress_h = 5;
    
    [self.proView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addressView.mas_bottom);
        make.left.equalTo(self).offset(5);
        make.height.mas_equalTo(100);
        make.right.equalTo(self.stateBtn.mas_left).offset(-10);

    }];
    
    [self.orderTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.proView);
        make.left.equalTo(self.proView);
        make.size.mas_equalTo(CGSizeMake(label_w, label_h));
    }];
    
    
    [self.arriveTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.orderTimeLabel);
        make.right.equalTo(self.proView);
        make.size.equalTo(self.orderTimeLabel);
    }];
    
   
    
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.proView);
        make.height.mas_equalTo(progress_h);
        make.left.equalTo(self.proView).offset(label_w/2);
        make.right.equalTo(self.proView).offset(-label_w/2);

    }];
    
    [self.orderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.proView);
        make.left.equalTo(self.orderTimeLabel);
        make.size.equalTo(self.orderTimeLabel);
    }];
   
    [self.arriveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.orderLabel);
        make.right.equalTo(self.arriveTimeLabel);
        make.size.equalTo(self.arriveTimeLabel);
    }];
    
    
//    NSArray* formats = @[ @"H:|-10-[btnIcon(==25)]", @"V:|-17-[btnIcon(==25)]", @"H:[btnIcon]-10-[labelSendAddress]-10-|", @"V:|-0-[labelSendAddress(==60)]", @"H:|-45-[labelReGeocode]-10-|", @"V:[labelSendAddress][labelReGeocode]-0-|"];
//    NSDictionary* views = @{ @"btnIcon":self.btnIcon, @"labelSendAddress":self.labelSendAddress, @"labelReGeocode":self.labelReGeocode};
//    for (NSString* format in formats) {
//        NSArray* constraints = [NSLayoutConstraint constraintsWithVisualFormat:format options:0 metrics:nil views:views];
//        [self addConstraints:constraints];
//    }
}


-(void)changeMasonry{
    
    [self.reachBtn removeFromSuperview];
    [self.clientBtn removeFromSuperview];
    [self.merchantBtn removeFromSuperview];
    [self.routeBtn removeFromSuperview];

    
    [self addSubview:self.reachBtn];
    [self addSubview:self.clientBtn];
    [self addSubview:self.merchantBtn];
    [self addSubview:self.routeBtn];
    
    
    
    //如果是待取货
    if (_isWaitTake) {
        self.reachBtn.hidden = NO;
        self.clientBtn.hidden = YES;
        
        //如果是跑腿
        if (self.isWaimOrPaot) {
            
            NSArray *masonryViewArray = @[self.reachBtn,self.merchantBtn,self.routeBtn];
            
            [masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:15 leadSpacing:15 tailSpacing:15];
            
            // 设置array的垂直方向的约束
            [masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self.proView.mas_bottom).offset(0);
                make.height.mas_equalTo(40);
            }];
            
        }else{
            
            self.clientBtn.hidden = NO;
            
            NSArray *masonryViewArray = @[self.reachBtn,self.clientBtn,self.merchantBtn,self.routeBtn];
            
            [masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:15 leadSpacing:15 tailSpacing:15];
            
            // 设置array的垂直方向的约束
            [masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self.proView.mas_bottom).offset(0);
                make.height.mas_equalTo(40);
            }];
            
        }
        
        
    }else{
        
        self.reachBtn.hidden = YES;
        self.clientBtn.hidden = YES;
        
        //如果是跑腿
        if (self.isWaimOrPaot) {
            
            NSArray *masonryViewArray = @[self.merchantBtn,self.routeBtn];
            
            [masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:30 leadSpacing:20 tailSpacing:20];
            
            // 设置array的垂直方向的约束
            [masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self.proView.mas_bottom).offset(0);
                make.height.mas_equalTo(40);
            }];
            
        }else{
            
            self.clientBtn.hidden = NO;
            
            
            NSArray *masonryViewArray = @[self.clientBtn,self.merchantBtn,self.routeBtn];
            
            [masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:15 leadSpacing:15 tailSpacing:15];
            
            // 设置array的垂直方向的约束
            [masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self.proView.mas_bottom).offset(0);
                make.height.mas_equalTo(40);
            }];
            
        }
        
        
        
    }
    
}

-(void)setIsWaitTake:(BOOL)isWaitTake{
    
    _isWaitTake = isWaitTake;
    
//    [self changeMasonry];
}

/* 逆地理编码回调. */
- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response
{
    if (response.regeocode != nil)
    {
        self.labelReGeocode.text = response.regeocode.formattedAddress;
    }
}

#pragma mark =====================================================  property package
-(void)setEntity:(MOrder *)entity{
    if(entity){
//        _entity = entity;
        MSubOrder* item = (MSubOrder*)[entity.arraySubOrder firstObject];
        self.labelSendAddress.text = entity.address;
        if([WMHelper isEmptyOrNULLOrnil:entity.addressRoad]){
        if([WMHelper isEmptyOrNULLOrnil:item.phoneAddress]){
         self.labelReGeocode.text =  @"";
        }else{
            NSArray* empty = [item.phoneAddress componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
            if(empty.count == 2){
                AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];
                regeo.location = [AMapGeoPoint locationWithLatitude:[[empty lastObject] doubleValue] longitude:[[empty firstObject] doubleValue]];
                regeo.requireExtension = YES;
                regeo.radius = 1000;
                [self.search AMapReGoecodeSearch:regeo];
            }else{
              self.labelReGeocode.text =  @"";
            }
        }
        }else{
            self.labelReGeocode.text = entity.addressRoad;
        }
    }
}

- (void)setWaiMaiDodelHList:(WJWaiMaiDodelHList *)waiMaiDodelHList
{

    if(waiMaiDodelHList){
        self.isWaimOrPaot = YES;
        [self changeMasonry];

        _waiMaiDodelHList = waiMaiDodelHList;
//        self.labelSendAddress.text = waiMaiDodelHList.send_address;
        self.labelReGeocode.text = waiMaiDodelHList.map_location;
        self.labelSendAddress.text = [NSString stringWithFormat:@"%@/%@",waiMaiDodelHList.user_name,waiMaiDodelHList.user_phone];

        if ([waiMaiDodelHList.fan_status integerValue] == 6) {
            
            [_reachBtn setTitle:@"上报到店" forState:UIControlStateNormal];
            
        }else{
            
            [_reachBtn setTitle:@"确认取货" forState:UIControlStateNormal];
            
        }

        
        
        self.arriveTimeLabel.text = waiMaiDodelHList.order_end_time;
        self.orderTimeLabel.text = waiMaiDodelHList.order_start_time;
        if ([waiMaiDodelHList.rate floatValue] > 1.0) {
            self.progressView.progress = 1.0;
            
        }else{
            self.progressView.progress = [waiMaiDodelHList.rate floatValue];
        }
        
        NSString *now = [CommonUntils currentDateStr];
        NSString *end = [CommonUntils getDateStringWithTimeStr:waiMaiDodelHList.order_end_time_stamp];
        
//        NSLog(@"%@",now);
//        NSLog(@"end = %@",end);
//        NSLog(@"order_end_time_stamp = %@",waiMaiDodelHList.order_end_time_stamp);

        int result = [CommonUntils compareDate:now withDate:end];
//        result = -1;
//        waiMaiDodelHList.order_end_time_stamp = @"1466386162";
//        [kCountDownManager start];

        if (result == 1) {//送达时间大于当前时间
            
            NSString *time = [CommonUntils dateFromNowDate:waiMaiDodelHList.order_end_time_stamp];
//            NSLog(@"time = %@",time);

            waiMaiDodelHList.timeCount = [time intValue];
            waiMaiDodelHList.isTimeOut = NO;
            // 手动刷新数据
            // 监听通知
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countDownNotification) name:OYCountDownNotification object:nil];
            
        }else if (result == -1){//送达时间小于当前时间  说明已超时
 
            NSString *time = [CommonUntils dateFromOutDate:waiMaiDodelHList.order_end_time_stamp];
            waiMaiDodelHList.timeCount = [time intValue];
            waiMaiDodelHList.isTimeOut = YES;
            
            int hour = [time intValue]/3600;
            if (hour >= 10) {
                [[NSNotificationCenter defaultCenter] removeObserver:self name:OYCountDownNotification object:nil];

//                [kCountDownManager invalidate];
                [self.stateBtn setTitle:@"已超时" forState:UIControlStateNormal];
                
            }else{
                // 手动刷新数据
                // 监听通知
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countDownNotification) name:OYCountDownNotification object:nil];

                
            }
            
        }else{
            
            
        }
        
     
        
        
    }
}
- (void)setWaiMaiDodelList:(WJWaiMaiDodelList *)waiMaiDodelList
{

    if(waiMaiDodelList){
        
        self.isWaimOrPaot = NO;
        [self changeMasonry];

        _waiMaiDodelList = waiMaiDodelList;
//        self.labelSendAddress.text = waiMaiDodelList.sendaddress;
        self.labelReGeocode.text = waiMaiDodelList.address_road;
        self.labelSendAddress.text = [NSString stringWithFormat:@"%@/%@",waiMaiDodelList.user_name,waiMaiDodelList.user_phone];

        if ([waiMaiDodelList.fan_status integerValue] == 6) {
            
            [_reachBtn setTitle:@"上报到店" forState:UIControlStateNormal];

        }else{
            
            [_reachBtn setTitle:@"确认取货" forState:UIControlStateNormal];

        }

        
        self.arriveTimeLabel.text = waiMaiDodelList.order_end_time;
        self.orderTimeLabel.text = waiMaiDodelList.order_start_time;
        if ([waiMaiDodelList.rate floatValue] > 1.0) {
            self.progressView.progress = 1.0;

        }else{
            self.progressView.progress = [waiMaiDodelList.rate floatValue];
        }
        
        
        NSString *now = [CommonUntils currentDateStr];
        NSString *end = [CommonUntils getDateStringWithTimeStr:waiMaiDodelList.order_end_time_stamp];
        
//        NSLog(@"%@",now);
//        NSLog(@"end = %@",end);
//        NSLog(@"order_end_time_stamp = %@",waiMaiDodelList.order_end_time_stamp);
//        [kCountDownManager start];

        int result = [CommonUntils compareDate:now withDate:end];
        if (result == 1) {//送达时间大于当前时间
            
            NSString *time = [CommonUntils dateFromNowDate:waiMaiDodelList.order_end_time_stamp];
            waiMaiDodelList.timeCount = [time intValue];
            waiMaiDodelList.isTimeOut = NO;
            // 手动刷新数据
            // 监听通知
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countDownListNotification) name:OYCountDownNotification object:nil];
            
        }else if (result == -1){//送达时间小于当前时间  说明已超时
            
            NSString *time = [CommonUntils dateFromOutDate:waiMaiDodelList.order_end_time_stamp];
            waiMaiDodelList.timeCount = [time intValue];
            waiMaiDodelList.isTimeOut = YES;
            
            
            int hour = [time intValue]/3600;
            if (hour >= 10) {
                [[NSNotificationCenter defaultCenter] removeObserver:self name:OYCountDownNotification object:nil];

//                [kCountDownManager invalidate];
                [self.stateBtn setTitle:@"已超时" forState:UIControlStateNormal];

            }else{
                // 手动刷新数据
                // 监听通知
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countDownListNotification) name:OYCountDownNotification object:nil];

                
            }
            
        }else{
            
            
        }
        
        
        
        
        
        
    }
}



//上报到店
-(void)reachBtnClick:(UIButton *)button{
    
    if (self.reachBlock) {
    
        self.reachBlock(self.isWaimOrPaot,button.titleLabel.text, self.waiMaiDodelHList, self.waiMaiDodelList);
    }
    
}

//线路规划
-(void)routeBtnClick:(UIButton *)button{
   
    if (self.routeBlock) {
        self.routeBlock(self.isWaimOrPaot, self.waiMaiDodelHList, self.waiMaiDodelList);
    }
    
}


//联系顾客
-(void)clientBtnClick:(UIButton *)button{
    
    NSString *phoneNum = @"";
    if(self.isWaimOrPaot){

        phoneNum = _waiMaiDodelHList.user_phone;
        
    }else{
        
        phoneNum = _waiMaiDodelList.user_phone;

    }
    
    NSMutableString* str = [[NSMutableString alloc] initWithFormat:@"tel:%@",phoneNum];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self  addSubview:callWebview];
    
    
}

//联系商家
-(void)merchantBtnClick:(UIButton *)button{
    
    NSString *phoneNum = @"";
    if(self.isWaimOrPaot){
        
        phoneNum = _waiMaiDodelHList.user_phone;
        
    }else{
        
        WJWaiMaiDodelListitems *waiMaiDodelListitems = _waiMaiDodelList.items.firstObject;
        phoneNum = waiMaiDodelListitems.site_phone;
        
    }
    NSMutableString* str = [[NSMutableString alloc] initWithFormat:@"tel:%@",phoneNum];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self  addSubview:callWebview];
    
}





-(UIButton *)btnIcon{
    if(!_btnIcon){
        _btnIcon = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnIcon setImage:[UIImage imageNamed:@"icon-sendStatus-light"] forState:UIControlStateNormal];
        _btnIcon.userInteractionEnabled = NO;
        _btnIcon.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _btnIcon;
}

-(UILabel *)labelSendAddress{
    if(!_labelSendAddress){
        _labelSendAddress = [[UILabel alloc]init];
        _labelSendAddress.font = [UIFont systemFontOfSize:14.f];
        _labelSendAddress.lineBreakMode = NSLineBreakByCharWrapping;
        _labelSendAddress.numberOfLines = 0;
        _labelSendAddress.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelSendAddress;
}

-(TTTAttributedLabel *)labelReGeocode{
    if(!_labelReGeocode){
        _labelReGeocode = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
        _labelReGeocode.textColor = [UIColor grayColor];
        _labelReGeocode.font = [UIFont systemFontOfSize:12.f];
        _labelReGeocode.lineBreakMode = NSLineBreakByCharWrapping;
        _labelReGeocode.numberOfLines = 0;
        _labelReGeocode.translatesAutoresizingMaskIntoConstraints = NO;
        _labelReGeocode.verticalAlignment=TTTAttributedLabelVerticalAlignmentTop;

    }
    return _labelReGeocode;
}
-(UIView *)addressView{
    if(!_addressView){
        _addressView = [[UIView alloc]init];
    }
    return _addressView;
}
-(AMapSearchAPI *)search{
    if(!_search){
        _search = [[AMapSearchAPI alloc] init];
        _search.delegate = self;
    }
    return _search;
}

-(UIView *)proView{
    if(!_proView){
        _proView = [[UIView alloc]init];
    }
    return _proView;
}

-(MQGradientProgressView *)progressView{
    if(!_progressView){
        float w = SCREEN_WIDTH - 35 - 100 - 80;
        _progressView = [[MQGradientProgressView alloc] initWithFrame:CGRectMake(0, 0,  w, 5)];
        //    progressView.colorArr = @[(id)MQRGBColor(59, 221, 255).CGColor,(id)MQRGBColor(34, 126, 239).CGColor];
        _progressView.colorArr = @[(id)[UIColor blueColor]];
    }
    return _progressView;
}



-(TTTAttributedLabel *)orderTimeLabel{
    if(!_orderTimeLabel){
        _orderTimeLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _orderTimeLabel.font = [UIFont systemFontOfSize:17.f];
        _orderTimeLabel.textAlignment = NSTextAlignmentCenter;
        _orderTimeLabel.textColor  = RGB(23, 155, 193);
        _orderTimeLabel.verticalAlignment=TTTAttributedLabelVerticalAlignmentBottom;

    }
    return _orderTimeLabel;
}

-(TTTAttributedLabel *)orderLabel{
    if(!_orderLabel){
        _orderLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _orderLabel.font = [UIFont systemFontOfSize:13.f];
        _orderLabel.textAlignment = NSTextAlignmentCenter;
        _orderLabel.textColor  = [UIColor grayColor];
        _orderLabel.text = @"下单时间";
        _orderLabel.verticalAlignment=TTTAttributedLabelVerticalAlignmentTop;

    }
    return _orderLabel;
}

-(TTTAttributedLabel *)arriveTimeLabel{
    if(!_arriveTimeLabel){
        _arriveTimeLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _arriveTimeLabel.font = [UIFont systemFontOfSize:17.f];
        _arriveTimeLabel.textAlignment = NSTextAlignmentCenter;
        _arriveTimeLabel.textColor  =RGB(23, 155, 193);
        _arriveTimeLabel.verticalAlignment=TTTAttributedLabelVerticalAlignmentBottom;

    }
    return _arriveTimeLabel;
}

-(TTTAttributedLabel *)arriveLabel{
    if(!_arriveLabel){
        _arriveLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _arriveLabel.font = [UIFont systemFontOfSize:13.f];
        _arriveLabel.textAlignment = NSTextAlignmentCenter;
        _arriveLabel.textColor  =  [UIColor grayColor];
        _arriveLabel.text = @"预计到达时间";
        _arriveLabel.verticalAlignment=TTTAttributedLabelVerticalAlignmentTop;

    }
    return _arriveLabel;
}

-(UIButton *)stateBtn{
    if(!_stateBtn){
        _stateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_stateBtn setBackgroundColor:RGB(244, 155, 51)];
        _stateBtn.layer.cornerRadius = 35/2;
        _stateBtn.layer.masksToBounds = YES;
        _stateBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
    }
    return _stateBtn;
}


-(UIButton *)reachBtn{
    if(!_reachBtn){
        _reachBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_reachBtn setBackgroundColor:RGB(244, 155, 51)];
        _reachBtn.layer.cornerRadius = 5;
        _reachBtn.layer.masksToBounds = YES;
        _reachBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
        [_reachBtn addTarget:self action:@selector(reachBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _reachBtn;
}


-(UIButton *)clientBtn{
    if(!_clientBtn){
        _clientBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_clientBtn setBackgroundColor:RGB(244, 155, 51)];
        _clientBtn.layer.cornerRadius = 5;
        _clientBtn.layer.masksToBounds = YES;
        _clientBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
        [_clientBtn setTitle:@"联系顾客" forState:UIControlStateNormal];
        [_clientBtn addTarget:self action:@selector(clientBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _clientBtn;
}



-(UIButton *)merchantBtn{
    if(!_merchantBtn){
        _merchantBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_merchantBtn setBackgroundColor:RGB(244, 155, 51)];
        _merchantBtn.layer.cornerRadius = 5;
        _merchantBtn.layer.masksToBounds = YES;
        _merchantBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
        [_merchantBtn setTitle:@"联系商家" forState:UIControlStateNormal];
        [_merchantBtn addTarget:self action:@selector(merchantBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _merchantBtn;
}

-(UIButton *)routeBtn{
    if(!_routeBtn){
        _routeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_routeBtn setBackgroundColor:RGB(244, 155, 51)];
        _routeBtn.layer.cornerRadius = 5;
        _routeBtn.layer.masksToBounds = YES;
        _routeBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
        [_routeBtn setTitle:@"路线规划" forState:UIControlStateNormal];
        [_routeBtn addTarget:self action:@selector(routeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _routeBtn;
}


#pragma mark - 倒计时通知回调
- (void)countDownNotification {
    /// 判断是否需要倒计时 -- 可能有的cell不需要倒计时,根据真实需求来进行判断
    if (0) {
        return;
    }
    /// 计算倒计时
    WJWaiMaiDodelHList *model = self.waiMaiDodelHList;
    NSInteger timeInterval;
    if (model.countDownSource) {
        timeInterval = [kCountDownManager timeIntervalWithIdentifier:model.countDownSource];
    }else {
        timeInterval = kCountDownManager.timeInterval;
    }
    
//    int countDown = model.timeCount - timeInterval;
    int countDown = 0;
    if (model.isTimeOut) {
        
        countDown =  model.timeCount + timeInterval;
    }else{
        
        countDown =  model.timeCount - timeInterval;
        
    }
    
    /// 重新赋值
    //右侧等待支付
    NSString *restTime = [NSString stringWithFormat:@"%02d:%02d:%02d",(countDown/3600),(countDown/60)%60, countDown%60];
    NSString *time = [NSString stringWithFormat:@"剩余 %@",restTime];
  
    NSString *outtime = [NSString stringWithFormat:@"已超时 %@",restTime];
    
    if (model.isTimeOut) {
        
        [self.stateBtn setTitle:outtime forState:UIControlStateNormal];
        int hour = [time intValue]/3600;
        if (hour >= 10) {
            [self.stateBtn setTitle:@"已超时" forState:UIControlStateNormal];
        }
        
    }else{
        
        [self.stateBtn setTitle:time forState:UIControlStateNormal];
         if (countDown <= 0) {/// 当倒计时到了进行回调
             // 回调给控制器
             if (self.countDownZero) {
                 self.countDownZero(model);
             }

         }
    }
    
    
    
}

- (void)countDownListNotification {
    /// 判断是否需要倒计时 -- 可能有的cell不需要倒计时,根据真实需求来进行判断
    if (0) {
        return;
    }
    /// 计算倒计时
    WJWaiMaiDodelList *model = self.waiMaiDodelList;
    NSInteger timeInterval;
    if (model.countDownSource) {
        timeInterval = [kCountDownManager timeIntervalWithIdentifier:model.countDownSource];
    }else {
        timeInterval = kCountDownManager.timeInterval;
    }
    
    
    int countDown = 0;
    if (model.isTimeOut) {
        
        countDown =  model.timeCount + timeInterval;
    }else{
        
        countDown =  model.timeCount - timeInterval;

    }
    
   
    /// 重新赋值
    //右侧等待支付
    NSString *restTime = [NSString stringWithFormat:@"%02d:%02d:%02d",(countDown/3600),(countDown/60)%60, countDown%60];
    NSString *time = [NSString stringWithFormat:@"剩余 %@",restTime];
    NSString *outtime = [NSString stringWithFormat:@"已超时 %@",restTime];

    if (model.isTimeOut) {
        
        [self.stateBtn setTitle:outtime forState:UIControlStateNormal];

    }else{
        
        [self.stateBtn setTitle:time forState:UIControlStateNormal];
        /// 当倒计时到了进行回调
        if (countDown <= 0) {
            
            // 回调给控制器
            if (self.countDownListZero) {
                self.countDownListZero(model);
            }
            
            return;
        }
    }
    

    
}


- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}






@end
